package com.waitingresult.controller;

import com.waitingresult.config.MqConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-10-20  19:50
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("test")
public class TestController {
    @Autowired
    public RabbitTemplate rabbitTemplate;

    @RequestMapping("fanout")
    public String publish() {
        rabbitTemplate.convertAndSend(MqConfig.FANOUT_EXCHANGE_DEMO, null, "message");
        System.out.println("fanout 消息发送成功");
        return "fanout--ok";
    }

    @RequestMapping("publishWithProps")
    public String publishWithProps() {
        rabbitTemplate.convertAndSend(MqConfig.FANOUT_EXCHANGE_DEMO, "big.black.dog", "messageWithProps", message -> {
            message.getMessageProperties().setCorrelationId("123");
            return message;
        });
        System.out.println("消息发送成功");
        return "publishWithProps--ok";
    }
}
